<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${generator.packageName}.mapper.${generator.className}RelationMapper">

    <resultMap type="${generator.packageName}.entity${generator.childPackageName}.relation.${generator.className}RelationDO" id="baseResultMap">
    	<#list columns as row>
      <<#if row.columnKey == 'PRI'>id<#else>result</#if> column="${generator.tableName}_${row.columnName}" property="${row.javaName}"/>
    	</#list>
      <#if relations??>
        <#list relations?keys as key>
          <#list relations[key] as row>
      <result column="${key!}_${row.columnName}" property="${row.javaName}"/>
          </#list>
        </#list>
      </#if>
    </resultMap>

    <select id="getRelation" resultMap="baseResultMap">
      SELECT
      <#list columns as column>
      <#if column_index = 0>
      ${generator.tableName}.`${column.columnName}` AS ${generator.tableName}_${column.columnName}
      <#else>
      , ${generator.tableName}.`${column.columnName}` AS ${generator.tableName}_${column.columnName}
      </#if>
      </#list>
      <#if relations??>
        <#list relations?keys as key>
          <#list relations[key] as row>
      , ${key!}.`${row.columnName}` AS ${key!}_${row.columnName}
          </#list>
        </#list>
      </#if>
      FROM ${generator.tableName}
      <#if relations??>
        <#list relations?keys as key>
      LEFT JOIN ${key!} ON ${generator.tableName}.`id` = ${key!}.`id`
        </#list>
      </#if>
      ${r'${ew.customSqlSegment}'}
	  </select>
</mapper>
